package com.swy.config.clientdetailsservicestrategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * @Author:Xujingjian
 * @时间: 2018/10/22
 * @描述:
 */

@Component
public class InMemoryServiceStrategy implements IClientDetailsServiceStrategy{

    @Autowired
    private PasswordEncoder passwordEncoder;


    public ClientDetailsService clientDetailsService() {
        /**
         * 通过分析JdbcClientDetailsService，知道此服务主要是对客户端注册明细(oauth_client_details)表的增删改查操作
         */
        return new InMemoryClientDetailsService();
    }

    public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
        //内存保存clientId信息
        clients.inMemory()
                .withClient("client_1")
                .secret(passwordEncoder.encode("123456"))
                .authorizedGrantTypes("authorization_code","client_credentials","password","refresh_token")
                .scopes("login")
                .autoApprove(true);
    }

}
